﻿using EFCore.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using SIService;
using SService;

namespace WMSWeb.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class InventoryController : ControllerBase
    {
        private readonly WmssystemContext myDbContext;
        private readonly InventoryS InventoryS;

        public InventoryController(WmssystemContext myDbContext, InventoryS InventoryS)
        {
            this.myDbContext = myDbContext;
            this.InventoryS = InventoryS;
        }
        /// <summary>
        /// 盘点分页模糊查询
        /// </summary>
        /// <returns></returns>
        [HttpGet("FenYe")]
        public async Task<List<sys_inventory>> FenYe(int pageSize, int currentPage, string code = null, int? result = null, int? type = null, int? wid = null)
        {
            return await InventoryS.FenYe(pageSize, currentPage, code, result,type,wid);
        }
        /// <summary>
        /// 盘点添加
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult<int>> Add(sys_inventory add)
        {
            // 为实体的属性赋值
            add.i_iisdelete = true;
            // 调用服务层的方法执行添加操作
            return await InventoryS.Add(add);
        }
        /// <summary>
        /// 盘点逻辑删除
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdIsDelete")]
        public async Task<ActionResult<int>> UpdIsDelete(int id, bool isDeleted)
        {
            return await InventoryS.UpdIsDelete(id, isDeleted);
        }
        /// <summary>
        /// 盘点审核
        /// </summary>
        /// <returns></returns>
        [HttpPut]
        public async Task<int> RkShen(sys_inventory sys_inventory, string to)
        {
            return await InventoryS.RkShen(sys_inventory, to);
        }
        /// <summary>
        /// 盘点撤回
        /// </summary>
        /// <returns></returns>
        [HttpPut("UpdShen")]
        public async Task<ActionResult<int>> UpdShen(int id, int shen)
        {
            return await InventoryS.UpdShen(id, shen);
        }
        /// <summary>
        /// 盘点修改
        /// </summary>
        /// <returns></returns>
        [HttpPut("Upd")]
        public async Task<int> Upd(sys_inventory sys_inventory)
        {
            sys_inventory.i_iupdateuser = 1;
            sys_inventory.i_iupdatetime = new DateTime();

            return await InventoryS.Upd(sys_inventory);
        }
    }
}
